package com.senmiao.ssm.controller;

import com.senmiao.ssm.aspect.annotation.DoAuthorizeLog;
import com.senmiao.ssm.aspect.annotation.DoQueryLog;
import com.senmiao.ssm.service.SecuritySecrecyService;
import com.senmiao.ssm.utils.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 安全保密员controller
 */
@RestController
public class SecuritySecrecyController {

    @Autowired
    private SecuritySecrecyService securitySecrecyService;

    /**
     * 给角色赋予权限
     * @param roleId
     * @param permissionIds
     * @return
     */
    @RequiresPermissions("/admin/role/authorize:post")
    @DoAuthorizeLog(tableName = "tb_role_permission")
    @RequestMapping("/admin/role/authorize")
    public Result authorizeRole(Integer roleId,@RequestParam(value = "permissionId",required = false) List<String> permissionIds){
        return securitySecrecyService.authorizeAdminRole(roleId,permissionIds);
    }

    /**
     * 获取管理员已有权限
     * @param adminId
     * @return
     */
    @RequiresPermissions("/admin/permission/have:get")
    @RequestMapping("/admin/permission/have")
    public Result getAdminHavePermission(Integer adminId){
        return securitySecrecyService.getAdminHavePermission(adminId);
    }

    /**
     * 获得角色的权限
     * @param roleId
     * @return
     */
    @RequiresPermissions("/admin/role/permission:get")
    @RequestMapping("/admin/role/permission")
    public Result getRolePermission(Integer roleId){
        return securitySecrecyService.getRolePermission(roleId);
    }

    /**
     * 获取业务管理员和审计管理员的日志列表
     * @param pageNum
     * @param limit
     * @return
     */
    @RequiresPermissions("/admin/log/businessAndAudit/getList:get")
    @DoQueryLog(tableName="tb_operate_log")
    @RequestMapping("/admin/log/businessAndAudit/getList")
    public Result listBusinessAndAuditOperatorLog(Integer pageNum,Integer limit){
        return securitySecrecyService.listBusinessAndAuditOperatorLog(pageNum,limit);
    }

    /**
     * 查看管理员操作日志列表
     * @param pageNum
     * @param limit
     * @return
     */
    @RequiresPermissions("/admin/log/admin/getList:get")
    @DoQueryLog(tableName = "tb_operate_log")
    @RequestMapping("/admin/log/admin/getList")
    public Result listAdminLog(Integer pageNum,Integer limit){
        return securitySecrecyService.listAdminLog(pageNum,limit);
    }

}